package com.common.library.Utils;

import android.content.Context;

import com.common.library.App;


/**
 * Created by Administrator on 2017/11/2 0002.
 */

public class SpUtil {

    public static Context getContext() {
        return App.getInstance().getApplicationContext();
    }

    public static String getSpName() {
        return App.getInstance().getSpName();
    }

    public static boolean getBoolean(String key, boolean defValue) {
        return getContext()
                .getSharedPreferences(getSpName(), Context.MODE_PRIVATE)
                .getBoolean(key, defValue);
    }

    public static void putBoolean(String key, boolean value) {
        getContext().getSharedPreferences(getSpName(), Context.MODE_PRIVATE)
                .edit()
                .putBoolean(key, value)
                .commit();
    }

    public static String getString(String key, String defValue) {
        return getContext()
                .getSharedPreferences(getSpName(), Context.MODE_PRIVATE)
                .getString(key, defValue);
    }

    public static void putString(String key, String value) {
        getContext().getSharedPreferences(getSpName(), Context.MODE_PRIVATE)
                .edit()
                .putString(key, value)
                .commit();
    }

    public static void putInt(String key, int value) {
        getContext().getSharedPreferences(getSpName(), Context.MODE_PRIVATE)
                .edit()
                .putInt(key, value)
                .commit();
    }

    public static int getInt(String key, int defValue) {
        return getContext()
                .getSharedPreferences(getSpName(), Context.MODE_PRIVATE)
                .getInt(key, defValue);
    }


    public static Long getLong(String time, int i) {
        return getContext()
                .getSharedPreferences(getSpName(), Context.MODE_PRIVATE)
                .getLong(time, i);
    }

    public static void putLong(String time, long i) {
        getContext().getSharedPreferences(getSpName(), Context.MODE_PRIVATE)
                .edit()
                .putLong(time, i)
                .commit();
    }
}
